/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.atp.agencia.ui.controle.aluguel;

import br.com.atp.agencia.modelo.Aluguel;
import br.com.atp.agencia.modelo.Locatario;
import br.com.atp.agencia.modelo.Quarto;
import br.com.atp.agencia.util.DateUtil;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Afonso
 */
public class ControleQuarto extends JIFControlaAluguel {

    private Quarto q1;
    protected Locatario l1;

    public ControleQuarto(Quarto q11, boolean modo) {
        super(modo);
        this.q1 = q11;
        preencheDados();
    }

    @Override
    public void ocultaCampos() {
        jTFCamaExtra.setVisible(false);
        jLCamaExtra.setVisible(false);
    }

    @Override
    public void registraEntrada() {
        if (l1 == null) {
            l1 = new Locatario();
        }
        try {
            l1.setNome(jTFNome.getText());
            l1.setCpf(jFTCpf.getText());
            q1.setLocatario(l1);
            q1.setEntrada(DateUtil.makeDate(jFTDataEntrada.getText()));
            q1.setNumPessoas(Integer.parseInt(jTFNumPessoas.getText()));
            dispose();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(rootPane, "Valor informado é incorreto \n" + e.getMessage());
            q1.removeLocatario();
        }
    }

    @Override
    public void registraSaida() {
        calculaTotalGeral();
        try {
            JOptionPane.showMessageDialog(rootPane, q1.recibo());
            q1.removeLocatario();
            dispose();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(rootPane, "Valor informado é incorreto \n" + e.getMessage());
        }
        
    }

    @Override
    public void preencheDados() {
        if (!verificaModo()) {
            jFTCpf.setText(q1.getLocatario().getCpf());
            jFTDataEntrada.setText(DateUtil.getStringFromDate(q1.getEntrada(), DateUtil.formatoBR));
            jTFNome.setText(q1.getLocatario().getNome());
            jTFNumPessoas.setText(String.valueOf(q1.getNumPessoas()));
        }
    }

    @Override
    public void initObjects() {
        this.q1 = new Quarto();
        this.l1 = new Locatario();
    }

    @Override
    public void initLabels() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void calculaTotalGeral() {
        try {
            q1.setSaida(DateUtil.makeDate(jFTDataSaida.getText()));
            jTFTotalGeral.setText(String.valueOf(q1.getTotalDevido()));
        } catch (Exception e) {
            JOptionPane.showMessageDialog(rootPane, "Valor informado é incorreto \n" + e.getMessage());
        }
    }
}
